package com.example.cline.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

@Configuration
public class FilterConfig {
    private static final Logger LOGGER = LoggerFactory.getLogger(FilterConfig.class);

    @Bean
    public FilterRegistrationBean<GlobalLogFilter> globalLogFilter() {
        LOGGER.info("init logger filter");
        FilterRegistrationBean<GlobalLogFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(new GlobalLogFilter());
        registration.addUrlPatterns("/*"); // 拦截所有请求
        registration.setOrder(Ordered.HIGHEST_PRECEDENCE); // 最高优先级
        return registration;
    }
}